//define(['js/module.js','jquery'],function(controllers,$){
    'use strict';
	angular.module('backcenter.sysActionSingle', [])
    .controller('sysActionSingleCtrl'
			,[ '$rootScope', '$scope', 'BizData', '$uibModalInstance','params', 'title'
                                       ,f])
        function f($rootScope, $scope, BizData, $uibModalInstance, params, title
					   ) {

		var Model = this;

		/**
		name:bizData#onBeforeDelete
		description: <b>[回调型事件]</b>业务数据删除前
		@param {object} event 它的结构如下:<br/>
		{
			"source":组件的js对象
			,"cancel":可修改	，设置为true后中断当前delete动作
			,"deleteIDList":删除的行Id数组
		}
		*/
		Model.dataSysActionBeforeDelete = function(event) {
//			alert(event.deleteIDList[0]);
		}
		/**
		name:bizData#onAfterDelete
		description: <b>[回调型事件]</b>业务数据删除后
		@param {object} event 
		<br/><b>结构如下：</b>
		<xmp> 
		{
			"source" : 组件的js对象,
			"deleteIDList" : 删除的行Id数组
		}
		</xmp>	
		*/
		Model.dataSysActionAfterDelete = function(event) {
//			alert('删除之后！')
		}


		
		
		/**
		name:bizData#onIndexChanged
		description: <b>[回调型事件]</b>行记录变化
		@param {object} event 
		<br/><b>结构如下：</b>
		<xmp> 
		{
			"source" : 组件的js对象,
			"rowID" : 行Id,
			"rowIndex" : 行索引
		}
		</xmp>	
		*/
		Model.dataSysActionIndexChanged = function(event) {
		}
		
		/**
		name:bizData#onDataChanged
		description: <b>[回调型事件]</b>数据发生变化（包括新增、刷新、删除、修改引起的变化），感知从data的变化
		@param {object} event 
		<br/><b>结构如下：</b>
		<xmp> 
		{
			"source" : 组件的js对象,
			"changedSource" ：触发变化的组件的js对象，当从data触发时返回从data对象,
			"selfChanged" : 是否自身变化，false：从data触发的变化,
			"type" : 触发变化的类型，包括：new、delete、refresh、valueChanged、clear，其他参数根据触发类型不同给出不同参数，参考onAfterNew等事件参数
		}
		</xmp>	
		*/
		Model.dataSysActionDataChanged = function(event) {
		}
		
		/**
		name:bizData#onValueChanged
		description: <b>[回调型事件]</b>数据变化
		@param {object} event 
		<br/><b>结构如下：</b>
		<xmp> 
		{
			"source" : 组件的js对象,
			"column" : 关系,
			"rowIndex" : 行索引,
			"value" : 新值,
			"originalValue" : 旧值
		}
		</xmp>	
		*/
		//输入值变化，监视input的输入，ng-change
		Model.dataSysActionValueChanged = function(event) {

		}
		

		
		
		
		//定义页面级别的变量
//		var systemCode; //系统代码
//		var billType = 'GCDA';
//		var billTypeName = "";
//		var flowType = 0;
//		var autoCode; //是否自动编码
//		var revOpay; //入库出库
//		var direction;
//		var costingCode; //影响成本码
//		var origin;
//		var originName = "";
//		var billNo = "";

		/**
		name:bizData#onBeforeNew
		description: <b>[回调型事件]</b>业务数据新增前
		@param {object} event 它的结构如下:<br/>{"source":组件的js对象,"cancel":可修改，设置为true后中断当前new动作}
		 */
		Model.dataSysActionBeforeNew = function(event) {
		};
		/**
		 * name:bizData#onAfterNew description: <b>[回调型事件]</b>业务数据新增后
		 * 
		 * @param event
		 *            它的结构如下:<br/>{"source":组件的js对象,"id":新增的行Id}
		 */
		Model.dataSysActionAfterNew = function(event){
			/*
			//创建行后赋值
			event.source.setValue('systemCode',systemCode,event.id);
			event.source.setValue('billType',billType,event.id);
			event.source.setValue('billTypeName',billTypeName,event.id);
			if (autoCode = "Y"){
				//产生自动流水号
				event.source.setValue('factoryNo',$scope.billNo,event.id);
			}
			*/
		}

		Model.dataSysActionAfterSave = function(event) {
			//保存成功
			$uibModalInstance.close(0);
		};
		
	
		
		//////////////////////对话框使用开始//////////////////////////////////////
        //模态窗口打开之后执行的事件
        $uibModalInstance.opened.then(function(){
    		//接收调用对话框的参数
            Model.title = title;  
            Model.params = params;  
//    	    $scope.dataSysAction.selected = {  
//    	        item: $scope.dataSysAction.items[0]  
//    	    };  
    		 
    		if(Model.params.recordState=='new'){
    			$scope.dataSysAction.loadData('');
	   		     var options = {
				         index : 0,
				         defaultValues : [
				             {
//				            	 state:'active'
//				            	 ,status:'open'
//				            	 ,audit:'active'
				            	 
				            	 systemFullID:params.id//'data'
//				            	 ,sSequence:0
//				            	 ,sValidState:1
				            	 
				            	 ,version:0
				            }//,
	//			             {itemNo:'a2',itemDescribe:'b2'}
				         ]
				     };    
	
				$scope.dataSysAction.newData(options);
    		}
    		if(Model.params.recordState=='edit'){
//    			$scope.dataSysAction.filter = "sID='"+params.id+"'";
    			$scope.dataSysAction.id = Model.params.id;
    		    $scope.dataSysAction.refreshData();
    		}
        });  
		 
        Model.ok = function () {  
	    	$scope.dataSysAction.saveData();
	    };  
	    
	    Model.cancel = function () {  
	        $uibModalInstance.dismiss('cancel');  
	    };    
		//////////////////////对话框使用结束//////////////////////////////////////

	    
		
		var options = {};
		options.container = Model;
		options.concept = 'SysAction';
		options.name = 'dataSysAction';
		options.url = $rootScope.path;
		options.httpUrl = $rootScope.getServiceName();
		options.creater = '/backcenter/sysAction/list/create';
		options.reader = '/backcenter/sysAction/list/query';
		options.writer = '/backcenter/sysAction/list/save';
		options.deleter = '/backcenter/sysAction/list/delete';
		options.idColumnDefine = "fID";
		options.idColumnName = "fID";
		options.defCols = {fID:{name:"fID",type:"String",label:""},systemFullID:{name:"systemFullID",type:"String",label:""},actionCode:{name:"actionCode",type:"String",label:""},actionName:{name:"actionName",type:"String",label:""},actionDescribe:{name:"actionDescribe",type:"String",label:""},version:{name:"version",type:"Integer",label:""}};
		options.isTree = false;
		options.parentRelation = 'sParent';
		options.nodeKindRelation = 'sNodeKind';
		options.nodeLevelRelation = 'sLevel';
		options.nodeSortRelation = "sSequence";
		options.pathRelation = 'sFID';
		options.directDeleteMode = false;
		options.limit = 10;
		
		options.onIndexChanging = null;
		options.onIndexChanged = Model.dataSysActionIndexChanged;
		options.onBeforeNew = Model.dataSysActionBeforeNew;
		options.onAfterNew = Model.dataSysActionAfterNew;
		options.onBeforeDelete = Model.dataSysActionBeforeDelete;
		options.onAfterDelete = Model.dataSysActionAfterDelete;
		options.onValueChanged = Model.dataSysActionValueChanged;
		options.onDataChanged = Model.dataSysActionDataChanged;
		options.onAfterSave = Model.dataSysActionAfterSave;
		
		$scope.dataSysAction = new BizData(options);

		//监视对象中的所有变动
		$scope.dataSysAction.deregRows = $scope.$watch('dataSysAction.rows',$scope.dataSysAction.watchRows,true);//true代表深度监视，包括对象的属性，而不是简单的一个值
		//////////////////////////////////////////////
		
		//接收调用的参数
//		Model.params = $rootScope.$stateParams;  
		
		
		return Model;
	    
	    
	}   
    
//})

